import request from '@/utils/request'
import type {
  UserResponseData,
  User,
  RoleListResponseData,
  RoleVo
} from './type'
enum API {
  GETUSERINFO_URL = '/admin/acl/user/',
  ADDUSER_URL = '/admin/acl/user/save',
  UPDATEUSER_URL = '/admin/acl/user/update',
  GETROLE_URL = '/admin/acl/user/toAssign/',
  SETASSIGNROLE_URL = '/admin/acl/user/doAssignRole',
  REMOVEUSER_URL = '/admin/acl/user/remove/',
  REMOVEUSERLIST_URL = '/admin/acl/user/batchRemove'
}

export const getAclUserService = (
  page: string | number,
  limit: string | number,
  name: string
) =>
  request.get<any, UserResponseData>(API.GETUSERINFO_URL + `${page}/${limit}`, {
    params: {
      name
    }
  })

// 新增用户
export const addUserService = (params: User) =>
  request.post(API.ADDUSER_URL, params)

// 更新用户
export const updateUserService = (params: User) =>
  request.put(API.UPDATEUSER_URL, params)

//  获取角色列表
export const getRoleListService = (adminId: string) =>
  request.get<any, RoleListResponseData>(API.GETROLE_URL + adminId)

// 分配角色
export const setUserRoleService = (roleVo: RoleVo) =>
  request.post(API.SETASSIGNROLE_URL, roleVo)

//删除用户
export const removeUserService = (id: string) =>
  request.delete(API.REMOVEUSER_URL + id)

// 批量删除用户
export const removeUserListService = (idList: string[]) =>
  request.delete(API.REMOVEUSERLIST_URL, { data: idList })
